//////////////////////////////////////////////////////////////////////////
// FileName:SysPhrase.aspx
// CreateBy:Fenky
// CreateDate:2009-11-04
// Description:
//		Set the SysPhrase
//
// Modify Log::
//	
// Copyright:ASL-MIS
/////////////////////////////////////////////////////////////////////////

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Common = Auto.Data.Common;
using Auto.Components;
using Auto.Web.Common;

namespace BaseSystem._System
{
    public partial class Order : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindListBox();
            }
        }
        private void BindListBox()
        {
            Common.SysPhrase phrase = new Common.SysPhrase();

            this.lbDetails.DataSource = phrase.GetDataDetailsByKey(SessionBox.CurrentSystem, Request.QueryString["PhraseID"], null);
            this.lbDetails.DataTextField = Common.SysPhrase.SysPhraseDetail.FIELD_PhraseText;
            this.lbDetails.DataValueField = Common.SysPhrase.SysPhraseDetail.FIELD_PhraseValue;
            this.lbDetails.DataBind();
        }

        protected void btnModify_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(hfValue.Value))
            {
                string[] orders = hfValue.Value.TrimEnd('|').Split('|');


                Common.SysPhrase phrase = new Common.SysPhrase();
                phrase.ListDetails = new List<Common.SysPhrase.SysPhraseDetail>();

                int i = orders.Length;

                Common.SysPhrase.SysPhraseDetail details = null;

                string sysID = SessionBox.CurrentSystem;
                string phraseID = Request.QueryString["PhraseID"];


                foreach (string order in orders)
                {
                    details = new Common.SysPhrase.SysPhraseDetail();
                    details.Order = i;
                    details.SysID = sysID;
                    details.PhraseID = phraseID;
                    details.PhraseValue = order;
                    phrase.ListDetails.Add(details);
                    i--;
                }
                phrase.UpdateDetailOrder(phrase.ListDetails);

                Jscript.AjaxRunJs(this, "window.parent.hidePopWinAndReload();");
                BindListBox();
            }
        }
    }
}
